package factoryMethodPattern;


import factoryMethodPattern.Pen.PenCore;
import factoryMethodPattern.ballPen.BallPen;
import factoryMethodPattern.ballPen.BlueBallPen;
import org.junit.Test;

/**
 * @program: course
 * @author: lsn
 * @create: 2024-03-24 19:01
 * @description: 工厂方法模式测试类
 */
public class ApiTest {
    int sharedVariable = 0;

    @Test
    public void factoryMethodPattern(){
        PenCore penCore;
        BallPen ballPen;
        ballPen = new BlueBallPen();
        penCore = ballPen.getPenCore();
        penCore.writeWord("hello");

    }

    @Test
    public void test1(){

        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                sharedVariable++;
            }
        });
        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 10000; i++) {
                sharedVariable++;

            }
        });

        thread1.start();
        thread2.start();

        try {
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("Final value of sharedVariable: " + sharedVariable);

    }

}

